package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.UserMapper;
import com.qf.entitys.User;
import com.qf.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer userId) {
        return 0;
    }

    @Override
    public int insert(User record) {
        return 0;
    }

    @Override
    public int insertSelective(User record) {
        return 0;
    }

    @Override
    public User selectByPrimaryKey(Integer userId) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return 0;
    }

    @Override
    public PageInfo<User> selectAll(Integer pageindex, User record) {
        if (pageindex == null || pageindex <= 0){
            pageindex =1;
        }
        PageHelper.startPage(pageindex,10);
        List<User> list = mapper.selectAll(record);
        for (User user :list){
            System.out.println(user);
        }
        //封装分页里的list数据属性
        PageInfo<User> businessPageInfo = new PageInfo<>(list);
        return businessPageInfo;
    }

    @Override
    public User loginPhone(String phone) {
        return mapper.loginPhone(phone);
    }

    @Override
    public User selectBypwd(String loginName, String loginPwd) {
        loginPwd = DigestUtils.md5DigestAsHex(loginPwd.getBytes());
        return mapper.loginpwd(loginName,loginPwd);
    }
    @Override
    public int insertUserbirthday(String loginname,String day) {
        return mapper.updateUserbirthday(loginname,day);
    }
}